package com.neouton.crm.pm.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neouton.common.entity.ActivitiVO;
import com.neouton.crm.customer.entity.CustomerVO;
import com.neouton.crm.entity.SysUserEntity;
import com.neouton.crm.op.entity.SalesOpportunityVO;
import com.neouton.crm.pm.entity.*;
import com.neouton.crm.sales.entity.SalesFileRelationVO;
import com.neouton.crm.salesTarget.entity.SalesTargetVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

/**
* @author 巾凡
* @description 针对表【sales_project_manage(项目管理表)】的数据库操作Mapper
* @createDate 2022-11-11 09:44:40
* @Entity com.neouton.crm.pm.entity.SalesProjectManage
*/
@Mapper
public interface SalesProjectManageMapper {

    /**
     * 查寻项目信息
     * @param page
     * @param projectManageVO
     * @param userList
     * @return
     */
    IPage<SalesProjectManageVO> queryProject(@Param("page") IPage page, @Param("projectManageVO") SalesProjectManageVO projectManageVO, @Param("userList") List<SysUserEntity> userList);

    List<SalesProjectManageVO> queryProject(@Param("projectManageVO") SalesProjectManageVO projectManageVO, @Param("userList") List<SysUserEntity> userList);

    SalesProjectManageVO queryProjectInfoByOppId(Integer oppId);

    IPage<SalesProjectManageVO> queryProjectAudit(@Param("page") IPage page, @Param("projectManageVO") SalesProjectManageVO projectManageVO);

    /**
     * 查寻Total
     * @param projectManageVO
     * @param userList
     * @return
     */
    long queryTotal(@Param("projectManageVO") SalesProjectManageVO projectManageVO, @Param("userList") List<SysUserEntity> userList);

    /**
     * 查询项目中的机会信息
     * @return
     */
    List<SalesProjectManageVO> queryProjectOfOpportunity();
    SalesProjectManageVO  queryProjectApprovalByWorkId(@Param("workId")Integer workId);
    IPage<SalesProjectManageVO> queryTodoProjectsByPage(@Param("page") IPage page, @Param("projectManageVO") SalesProjectManageVO projectManageVO, @Param("activitis") List<ActivitiVO> activitis);

    /**
     *
     * @return
     */
    List<SysUserEntity> getUserInformation();

    int deleteByPrimaryKey(Long id);

    int insert(SalesProjectManageVO record);

    int insertSelective(SalesProjectManageVO record);

    SalesProjectManageVO selectByPrimaryKey(@Param("projectManageId")Integer projectManageId);

    List<SalesProjectManageVO> queryAllProjectInfo();

    SalesProjectManageVO queryHistoryProjectApprovalByApprovalId(@Param("workId")Integer workId);

    SalesProjectManageVO queryHistoryProjectApprovalOneByApprovalId(@Param("workId")Integer workId);

    int updateByPrimaryKeySelective(SalesProjectManageVO record);

    int updateByPrimaryKey(SalesProjectManageVO record);

    /**
     * 依据项目ID获取项目信息
     * @param projectID
     * @return
     */
    SalesProjectManageVO queryProjectByID(@Param("projectManageId") Integer projectID);

    /**
     * 获取全部项目信息
     * @return
     */
    List<SalesProjectManageVO> queryProjects(String source);

    List<SalesFileRelationVO> selectDocymentsByprojectId(@Param("projectManageId") Integer projectID);

    List<SysUserEntity> selectContactsByprojectId(@Param("projectManageId") Integer projectID);

    /**
     * 根据项目id 获取全部回款计划
     * @param id
     * @return
     */
    List<ContractInfoVO> getProjectAllBackmoneyPlan(Integer id);

    /**
     *
     */
    @Deprecated
    List<Map<String,Object>> selectAllProjectDocument(Integer projectManageId);

    Integer queryProjectHeadByProjectId(Integer projectManageId);

    void getContractLessor(CustomerVO contractLessor);

    int transforPrincipal(@Param("userId")Integer userId, @Param("list") List<SalesProjectManageVO> list);

    /**
     * 通过客户ID查询项目信息
     * @param customerId
     * @return
     */
    List<SalesProjectManageVO> queryProjectByCustomerId(int customerId);

    List<ContractInfoVO> getProjectAllBackmoneyPlanByProjectList(@Param("customerId")int customerId);

    List<ContractInfoVO> getProjectAllBackmoneyPlanByCustomerId(Integer customerId);

    List<SalesProjectManageVO> queryProjectBySupplierId(@Param("supplierId")int supplierId);

    void addProjectAndBusiness(@Param("businessId") Integer businessId,@Param("projectId") Integer projectId,@Param("reason") String reason );

    SalesProjectManageVO queryProjectAndBusinessInfo(@Param("projectId") Integer projectId);


    List<ProjectUpdateInfoVO> queryUpdateInfoByApproveId(@Param("approveId") Integer approveId);

    void saveUpdateInfoToDB(@Param("businessId") Integer businessId,@Param("projectUpdateInfoVOs") List<ProjectUpdateInfoVO> projectUpdateInfoVOs);

    List<ProjectUpdateInfoVO> queryUpdateInfoById(@Param("projectManageId") Integer projectManageId);

    List<ProjectUpdateInfoVO> queryUpdateInfoOnLineById(@Param("projectManageId") Integer projectManageId);

    void updateLastTimeAfterApprove(@Param("projectManageId") Integer projectManageId);

    void deleteUpdateInfoAfterRejection(@Param("projectManageId") Integer projectManageId);

    void insertUpdateInfoToDb(@Param("sql") String insertSql);

    void deleteInfoToDb(@Param("sql") String deleteSql);

    void updateInfoToDb(@Param("sql") String updateSql);

    void deleteUpdateInfo(@Param("projectUpdateInfoVO") ProjectUpdateInfoVO projectUpdateInfoVO);

    void updateStatusAfterSubmit(@Param("businessId") Integer businessId,@Param("projectId") Integer projectId);

    List<ProjectUpdateInfoVO> queryUpdateInfoListBySearch(@Param("projectUpdateInfoVO") ProjectUpdateInfoVO projectUpdateInfoVO);

    List<ProjectUpdateInfoVO> queryUpdateInfoNoSubmit(@Param("projectId") Integer projectId);
    /**
     * 查寻项目变更信息
     * @param page
     * @param projectManageVO
     * @param userList
     * @return
     */
    IPage<SalesProjectManageVO> queryUpdateProject(@Param("page") IPage page, @Param("projectManageVO") SalesProjectManageVO projectManageVO, @Param("userList") List<SysUserEntity> userList);

   // 项目变更提交后更改项目主表标识和状态
    void updateProjectStatus(@Param("projectId") Integer projectId,@Param("isSubmit") boolean isSubmit, @Param("status") int status);

    Integer queryApproveIdByManagerId(@Param("projectId") Integer projectId);

    void updateProjectStatusByApproveId(@Param("approvalId") Integer approvalId, @Param("status") int status);

    void deleteUpdateInfoAfterRevoke(@Param("approvalId") Integer approvalId);

    List<ProjectUpdateInfoVO> queryNeedUpdateInfoById(@Param("projectManageId") Integer projectManageId);

    List<SalesProjectManageVO> queryAllProjectsByUser(@Param("userList") List<SysUserEntity> userList);

    List<SalesProjectManageVO> queryAllProjects();

    SalesProjectManageVO selectProjectManageMoneyById(@Param("proId")Integer proId);
}
